define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ips/iplists/index' + location.search,
                    add_url: 'ips/iplists/add',
                    edit_url: 'ips/iplists/edit',
                    del_url: 'ips/iplists/del',
                    multi_url: 'ips/iplists/multi',
                    table: 'ips',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                visible: false,
                showExport: false,
                commonSearch: false,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'title', title: __('Title')},
                        {field: 'new_ip', title: __('Ip')},
                        {field: 'count', title: __('Count')},
                        {field: 'num', title: __('CountBet')},
                        {field: 'carrier', title: __('Carrier'), searchList: {"联通":__('联通'),"电信":__('电信'),"移动":__('移动'),"其他":__('其他')}, formatter: Table.api.formatter.normal},
                        {field: 'code', title: __('Code')},
                        {field: 'type', title: __('Type.name')},
                        {field: 'trueness', title: __('Trueness')},
                        {field: 'provice', title: __('Provice')},
                        {field: 'city', title: __('City')},
                        {field: 'company', title: __('Company')},
                        {field: 'is_remove', title: __('Is_remove'), formatter:function(value){
                                if (value == 0) {
                                    return '否';
                                } else if (value == 1) {
                                    return '是';
                                }
                            }},
                        {field: 'whiteswitch', title: __('Whiteswitch'),searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'blackswitch', title: __('Blackswitch'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});